<template>
    <div class="box">
      <h2>Son2 子组件</h2>
      从vuex中获取的值:<label>{{ count }}</label>
      <br />
      <button @click="subCount(1)">值-1</button>
      <button @click="subCount(5)">值-5</button>
      <button @click="subCount(10)">值-10</button>
      <button @click="changeCountAsync(888)">一秒后改成888</button>
      <button @click="changeTitle('12346')">改标题</button>
      <hr>
      <div>{{ filterList }}</div>

      <hr>
      <!-- <div>{{ user.userInfo.name }}</div>
      <div>{{ setting.theme }}</div> -->

      <div>user模块中的数据：{{ userInfo }}</div>
      <button @click="setUser({ name: 'xiaoli', age: 80})">更新个人信息</button>
      <button @click="setUserSecond({ name: '113', age: 60 })">一秒后更新信息</button>
      <div>setting模块中的数据：{{ theme }}</div>
      <button @click="setTheme('red')">更新主题色</button>
      <button @click="setThemeSecond('green')">一秒后更新主题色</button>

      <hr>
      <!-- 访问模块中的getters -->
      <div>{{ UpperCaseName }}</div>
    </div>
  </template>

<script>
import { mapState, mapMutations, mapActions, mapGetters } from 'vuex'
export default {
  name: 'Son2Com',
  computed: {
    // mapState 和 mapGetters 都是映射属性
    ...mapState(['count', 'user', 'setting']),
    ...mapState('user', ['userInfo']),
    ...mapState('setting', ['theme']),
    ...mapGetters(['filterList']),
    ...mapGetters('user', ['UpperCaseName'])
  },
  methods: {
    // mapMutations和mapActions 都是映射方法的
    ...mapMutations(['subCount', 'changeTitle']),
    // subCount (n) {
    //   this.subCount(n)
    // }
    ...mapActions(['changeCountAsync']),

    // 分模块映射
    ...mapMutations('setting', ['setTheme']),
    ...mapMutations('user', ['setUser']),
    ...mapActions('user', ['setUserSecond']),
    ...mapActions('setting', ['setThemeSecond'])
  }
}
</script>

  <style lang="css" scoped>
  .box {
    border: 3px solid #ccc;
    width: 400px;
    padding: 10px;
    margin: 20px;
  }
  h2 {
    margin-top: 10px;
  }
  </style>
